package com.im.partchat.topic.bean;

import com.im.partchat.R;
import com.im.partchat.utils.ValueUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class TopicBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2408390151461552572L;
	private String topicId;
	private String memberId;
	private String memberName;
	private AvatarBean memberAvatar;
	private String content;
	private List<AvatarBean> picture;
	private String createdAt;
	private String address;
	
	private boolean praised;
	private int praiseCount;
	private int commentCount;
	private List<CommentBean> praiseMembers;
	// client 自己定义的
	private String timeString;
	private int photoOriginalWidth;
	private int photoOriginalHeight;

	//距离，之所以不用float去接受，是因为只有near接口才返回distance，别的接口distance是null
	//用 ==null来判断是不是near接口，以区分距离正好==0的情况
	private String distance;
	
	public String getMemberId() {
		return memberId;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}

	public String getMemberName() {
		return memberName;
	}

	public void setMemberName(String memberName) {
		this.memberName = memberName;
	}

	public AvatarBean getMemberAvatar() {
		return memberAvatar;
	}

	public void setMemberAvatar(AvatarBean memberAvatar) {
		this.memberAvatar = memberAvatar;
	}

	public String getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(String createdAt) {
		this.createdAt = createdAt;
		try {
			timeString = ValueUtil.getTimeStringFromNow(ValueUtil
					.getTimeLong(createdAt));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			timeString = "";
			e.printStackTrace();
		}
	}

	public int getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(int commentCount) {
		this.commentCount = commentCount;
	}

	public String getTopicId() {
		return topicId;
	}

	public void setTopicId(String topicId) {
		this.topicId = topicId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTimeString() {
		return timeString;
	}

	public boolean isPraised() {
		return praised;
	}

	public void setPraised(boolean praised) {
		this.praised = praised;
	}

	public int getZanDrawable() {
		return praised ? R.drawable.listitem_praise
				: R.drawable.listitem_unpraise;
	}

	public int getZanColor() {
		return praised ? 0xffF46533 : 0xff999999;
	}

	public List<CommentBean> getPraiseMembers() {
		return praiseMembers == null ? new ArrayList<CommentBean>()
				: praiseMembers;
	}

	public void setPraiseMembers(List<CommentBean> praiseMembers) {
		this.praiseMembers = praiseMembers;
	}

	public int getPraiseCount() {
		return praiseCount;
	}

	public void setPraiseCount(int praiseCount) {
		this.praiseCount = praiseCount;
	}

	public int getPhotoOriginalHeight() {
		return photoOriginalHeight;
	}

	public void setPhotoOriginalHeight(int photoOriginalHeight) {
		this.photoOriginalHeight = photoOriginalHeight;
	}

	public int getPhotoOriginalWidth() {
		return photoOriginalWidth;
	}

	public void setPhotoOriginalWidth(int photoOriginalWidth) {
		this.photoOriginalWidth = photoOriginalWidth;
	}

	public List<AvatarBean> getPicture() {
		return picture;
	}

	public void setPicture(List<AvatarBean> picture) {
		this.picture = picture;
		if (picture != null && picture.size() == 1) {
			try {
				String urlWithOutPng = picture.get(0).findOriginalUrl()
						.substring(0,picture.get(0).findOriginalUrl().lastIndexOf("."));
				String str = urlWithOutPng.substring(
						urlWithOutPng.lastIndexOf(".") + 1,
						urlWithOutPng.length());
				String[] zu = str.split("\\_");
				photoOriginalWidth = Integer.parseInt(zu[0]);
				photoOriginalHeight = Integer.parseInt(zu[1]);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getDistance() {
		return distance;
	}

	public void setDistance(String distance) {
		this.distance = distance;
	}
	
	//转为可以直接显示距离
	public String getDistanceString() {
		try {
			float distanceFloat = Float.parseFloat(distance);
			if (distanceFloat > 1000) {
				float km = (float) (Math.round((distanceFloat / 1000.0) * 10)) / 10;
				return km + "公里";
			} else if (distanceFloat < 50) {
				return "50米以内";
			} else {
				return distanceFloat + "米";
			}
		} catch (Exception e) {
			// TODO: handle exception
			// 如果不是topic/near接口。服务器不会返回distance
		}
		return address;
	}

}
